// pages/settlemeny/index.js
const app =getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    paysuccess:true,
    datas:[],
    num:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  chooseParking(){
    wx.navigateTo({
      url: '/pages/map/iindex',
    })
    // wx.openLocation({
      
    //   latitude: 30.55,
    //   longitude: 80.55,
    //   name:'CBD停车场'
    // })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      datas:JSON.parse(this.options.shuju)
    })
    let num =0
    let datas = this.data.datas
    for(let i=0;i<datas.length;i++){
      num += datas[i].num*datas[i].money;
    }
    this.setData({
      num
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  toPaySuccess(){
    let that = this
    wx.showModal({
      title:'提示',
      content:'确认支付？',
      success:function(res){
        if(res.confirm){
          wx.request({
            url: app.globalData.basicUrl + 'user/WxRecharge/recharge',
           // url:"http://stcar.easy.echosite.cn/WxRecharge/recharge",
           method: "POST",
           data: {
             openId: app.globalData.openId,
             userId: wx.getStorageSync('userId'),
             money: that.data.num
           },
           success: function (res) {
             var orderId = this;
             console.log(res);
             wx.requestPayment({
               timeStamp: res.data.timeStamp,
               package: res.data.package,
               paySign: res.data.paySign,
               appId: res.data.appId,
               signType: res.data.signType,
               nonceStr: res.data.nonceStr,
               success: function (res) {
                 wx.showToast({
                   title: '充值成功',
                   duration: 2000,
                   success: function () {
                     setTimeout(() => {
                       wx.navigateBack({
                         delta: 1
                       })
                     }, 2000)
                   }
                 })
               }
             })
           },
           fail: function (error) {
             console.log(error);
             wx.showToast({
               title: '充值失败',
               duration: 2000,
               success: function () {
                 setTimeout(() => {
                   wx.navigateTo({
                     url: '/pages/ucenter/payList/index',
                   })
                 }, 2000)
               }
             })
           }
         })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})